package com.jinxin.platform.cdacscontrolmgr.controller;

import com.jinxin.platform.base.api.annotation.APCOSApi;
import com.jinxin.platform.base.api.annotation.APCOSApiOperation;
import com.jinxin.platform.base.api.constant.APCOSApiConstans;
import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.cdacscontrolmgr.bean.CdyardmgrCarInfo;
import com.jinxin.platform.cdacscontrolmgr.common.SysOrgInfo;
import com.jinxin.platform.cdacscontrolmgr.rpc.CdacscontrolmgrRpc;
import com.jinxin.platform.cdacscontrolmgr.service.ICdacscontrolkmgrCarInfoService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * All rights Reserved, Designed By www.beonelot.com
 *
 * @version: V1.0
 * @Copyright: www.beonelot.com Inc. All rights reserved.
 * @Description：
 * @Date: 2021-09-06
 * @Author: Lingnan
 **/
@APCOSApi(value = "车辆接口", developers = {"lingnan"}, description = "车辆接口")
@RestController
@RequestMapping("/cdacscontrolmgr/cdacscontrolmgrCarInfo")
@Slf4j
public class CdacscontrolmgrCarController {
    @Autowired
    private ICdacscontrolkmgrCarInfoService cdacscontrolkmgrCarInfoService;
    @Autowired
    private CdacscontrolmgrRpc cdyardmgrRpc;

    @APCOSApiOperation(value = "分页查询车辆", developers = {"lingnan"}, description = "分页查询车辆",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @GetMapping("/list")
    public Map<String,Object> list(@RequestParam int page, @RequestParam int limit,
                                   @RequestParam(name = "flag")String flag,
                                   @RequestParam(required = false,name = "province")String province,
                                   @RequestParam(required = false,name = "carNo")String carNo,
                                   @RequestParam(required = false,name = "yardId")String yardId,
                                   @RequestParam(required = false,name = "categoryId")String categoryId){
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("code",0);
        SysOrgInfo currentOrg = cdyardmgrRpc.getCurrentOrg();
        if(currentOrg == null){
            resultMap.put("msg","获取当前组织信息失败");
            resultMap.put("data", null);
            return resultMap;
        }
        HashMap param = new HashMap();
        param.put("page", page);
        param.put("limit", limit);
        param.put("flag", flag);
        param.put("province", province);
        param.put("carNo", carNo);
        param.put("orgId", currentOrg.getOrgId());
        param.put("yardId", yardId);
        param.put("categoryId", categoryId);
        resultMap.put("count", cdacscontrolkmgrCarInfoService.listPageCount(param));
        resultMap.put("data", cdacscontrolkmgrCarInfoService.listPage(param));
        return resultMap;
    }

    @APCOSApiOperation(value = "保存或修改车辆", developers = {"lingnan"}, description = "保存或修改车辆",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @PostMapping("/saveOrUpdate")
    public JsonResult saveOrUpdate(@RequestBody CdyardmgrCarInfo record){
        return cdacscontrolkmgrCarInfoService.saveOrUpdate(record);
    }

    @APCOSApiOperation(value = "删除车辆", developers = {"lingnan"}, description = "删除车辆",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @GetMapping("/delete")
    public JsonResult delete(String id){
        return cdacscontrolkmgrCarInfoService.delete(id);
    }

    @APCOSApiOperation(value = "查询所有车辆", developers = {"lingnan"}, description = "查询所有车辆",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @GetMapping("/listAll")
    public JsonResult listAll(){
        return JsonResult.ok(cdacscontrolkmgrCarInfoService.list(new HashMap()));
    }

}
